
#include "defines.h"
#include "video/Texture.h"
#include "video/Device.h"
#include <assert.h>

namespace KEngine
{
	Texture::Texture():_texture(0)
	{
		ZeroMemory(&_surfaceDesc, sizeof(_surfaceDesc));
	}

	Texture::~Texture()
	{
		KSafeRelease(_texture);
	}

	bool Texture::loadFromFile(Device* device , const char* filename)
	{
		KSafeRelease(_texture);
		_name = filename;
		if (FAILED(D3DXCreateTextureFromFile(device->getDevice(), filename, &_texture)))
			return false;

		assert(_texture->GetLevelCount() > 0);
		_texture->GetLevelDesc(0, &_surfaceDesc);

		return true;
	}

	void Texture::setTexture(ID3DTexture* tex)
	{
		KSafeRelease(_texture);
		_texture = tex;
	}

	unsigned int Texture::getWidth() const
	{
		return _surfaceDesc.Width;
	}

	unsigned int Texture::getHeight() const
	{
		return _surfaceDesc.Height;
	}

};
